package com.opgea.crm.web.security;
/*
public class JsonEntryPoint extends LoginUrlAuthenticationEntryPoint {
	private String redirectUrl;
	private static final Logger log = LoggerFactory.getLogger(JsonEntryPoint.class);
	
	
	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
		throws IOException, ServletException {
		
		String acceptHeader = request.getHeader("Accept");
		
		log.debug("Accect Header:{}",acceptHeader);
		log.debug("Content-Type:{}",request.getContentType());
		String contentType = request.getContentType();
		
		if (contentType!=null&&(contentType.toLowerCase().contains("json")
				||contentType.toLowerCase().contains("multipart/form-data"))) {
			if(contentType.toLowerCase().contains("multipart/form-data")){
				response.setContentType("text/html");
			}
			//ajax request, so use the Location header instead of standard 302 redirect
			log.debug("JSON Request setting 401 status instead of 302");
			
			HttpServletResponse httpResponse = (HttpServletResponse) response;
			
			httpResponse.setStatus(401);
			
			httpResponse.addHeader("Location", redirectUrl);
	        httpResponse.setHeader("Cache-Control", "private,no-cache,no-store");
	        httpResponse.setHeader("Pragma", "no-cache");
	        httpResponse.setDateHeader("Expires", 0);
	        HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response);
			Writer out = responseWrapper.getWriter();
			out.write("{ success: false, errors: { reason: 'You are not autorized to view this content.'}}");
	        out.close();
		}
		else {
			log.debug("Request was not a json request super commence will be executed.");
			super.commence(request, response, authException);
		}				
	}


	public String getRedirectUrl() {
		return redirectUrl;
	}


	public void setRedirectUrl(String redirectUrl) {
		this.redirectUrl = redirectUrl;
	}

		

}
*/